package com.ddtech.business.room.controller;


import com.alibaba.fastjson.JSONObject;
import com.ddtech.business.room.entity.Room;
import com.ddtech.business.room.query.RoomQuery;
import com.ddtech.business.room.service.RoomService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

/**
 * @version v1.0
 * @ClassName:RoomController description：
 * @author:wei_zhang(xiao)
 * @date: 2024-11-15 16:03
 */
@Api(tags = "业务-房间管理")
@RestController
@RequestMapping("/room")
public class RoomController {

    @Autowired
    private RoomService roomService;

    @ApiOperation(value = "创建房间")
    @PostMapping(value = "/create")
    public ResponseEntity create(@RequestBody Room room) {
        JSONObject json= new JSONObject();
        json.put("id",roomService.create(room));
        return new ResponseEntity(json, HttpStatus.OK);
    }

    @ApiOperation(value = "修改房间")
    @PostMapping(value = "/update")
    public ResponseEntity update(@RequestBody Room room) {
        roomService.update(room);
        return new ResponseEntity(true, HttpStatus.OK);
    }

    @ApiOperation(value = "删除房间")
    @PostMapping(value = "/del/{id}")
    public ResponseEntity del(@PathVariable String id) {
        roomService.del(id);
        return new ResponseEntity(true, HttpStatus.OK);
    }

    @ApiOperation(value = "进入业务模拟训练系统")
    @PostMapping(value = "/joinSystem")
    public ResponseEntity joinSystem() {
        roomService.joinSystem();
        return new ResponseEntity(true, HttpStatus.OK);
    }

    @ApiOperation(value = "离开业务模拟训练系统")
    @PostMapping(value = "/leaveSystem")
    public ResponseEntity leaveSystem() {
        roomService.leaveSystem();
        return new ResponseEntity(true, HttpStatus.OK);
    }

    @ApiOperation(value = "查询已进入业务系统在线人数")
    @GetMapping(value = "/getOnSystemUser")
    public ResponseEntity getOnSystemUser() {
        JSONObject json = new JSONObject();
        json.put("userNumber",roomService.getOnSystemUser());
        return new ResponseEntity(json, HttpStatus.OK);
    }

    @ApiOperation(value = "开始游戏")
    @GetMapping(value = "/startRoom/{id}")
    public ResponseEntity startRoom(@PathVariable String id) {
        roomService.startRoom(id);
        return new ResponseEntity(true, HttpStatus.OK);
    }

    @ApiOperation(value = "查询房间列表")
    @GetMapping(value = "/page-list")
    public ResponseEntity getPageList(RoomQuery roomQuery) {
        return new ResponseEntity(roomService.pageList(roomQuery), HttpStatus.OK);
    }

    @ApiOperation(value = "查询房间列表")
    @GetMapping(value = "/list")
    public ResponseEntity list(RoomQuery roomQuery) {
        return new ResponseEntity(roomService.list(roomQuery), HttpStatus.OK);
    }
}
